package ldh.im.dto.codec.binery;

import io.netty.buffer.ByteBuf;
import ldh.im.dto.business.ReConnection;

public class ReConnectionCodec extends AckToCodec<ReConnection> {

    @Override
    public void encode(ReConnection reConnection, ByteBuf byteBuf) {
        super.encode(reConnection, byteBuf);
        writeString(byteBuf, reConnection.getAuthToken());
    }

    @Override
    public void decode(ReConnection reConnection, ByteBuf byteBuf) {
        super.decode(reConnection, byteBuf);
        reConnection.setAuthToken(readString(byteBuf));
    }

    @Override
    public ReConnection create() {
        return new ReConnection();
    }

    @Override
    public int getAuthCode() {
        return "reconnection".hashCode();
    }

    @Override
    protected void checkEncode(ReConnection reConnection) {
        super.checkEncode(reConnection);
        if (reConnection.getAuthToken() == null || reConnection.getAuthToken().trim().equals("")) {
            throw new RuntimeException("请赋值AuthToken");
        }
    }
}
